package com.lesso.zgs.sunflower.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.core.ApiResponse;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeDeviceDTO;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeDeviceQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.EmployeeDeviceVO;
import com.lesso.zgs.sunflower.service.IEmployeeDeviceService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 员工设备关系 前端控制器
 * </p>
 *
 * @author zgs
 * @since 2025-07-03
 */
@RestController
@RequestMapping("/employee/device")
public class EmployeeDeviceController {
    @DubboReference
    private IEmployeeDeviceService employeeDeviceService;

    /**
     * 为员工授权设备
     */
    @PostMapping("/authorize")
    public ResponseEntity<Integer> authorizeDevice(@RequestBody EmployeeDeviceDTO dto) {
        return ResponseEntity.ok(employeeDeviceService.authorizeDevice(dto));
    }

    /**
     * 取消员工设备授权
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> cancelAuthorization(@PathVariable Long id) {
        return ResponseEntity.ok(employeeDeviceService.cancelAuthorization(id));
    }

    /**
     * 分页查询员工设备关系
     */
    @GetMapping("/page")
    public ApiResponse<Page<EmployeeDeviceVO>> page(EmployeeDeviceQueryDTO dto) {
        return ApiResponse.ok("success", employeeDeviceService.page(dto));
    }

    /**
     * 根据员工ID查询设备
     */
    @GetMapping("/employee/{employeeId}")
    public ApiResponse<List<EmployeeDeviceVO>> getByEmployeeId(@PathVariable Long employeeId) {
        return ApiResponse.ok("success", employeeDeviceService.getByEmployeeId(employeeId));
    }
} 